import request from "@/service/request";
import {PromisePageResponse, PromiseResponse} from "@/service/api/type.ts";
import {
  SchoolSiteHomePageVo,
  SysDictDataVo, SysOrganizationVo,
} from "@/service/api/school/image/types.ts";
import {
  SchoolSiteArticleVo,
} from "@/service/api/school/news/types.ts";


/**
 * 获取根组织列表
 * @param query
 */
const getRootOrganizationList = (
    query: any,
): PromisePageResponse<SysOrganizationVo> => {
  return request({
    url: "/system/organization/list",
    method: "get",
    params: query,
  });
};

/**
 * 获取根组织类型
 */
const getRootOrganizationTypeList = (): PromisePageResponse<SysDictDataVo> => {
  return request({
    url: "/system/dict/data/list",
    method: "get",
    params: {
      dictType: "organization_type",
      parentId: 0
    },
  });
};

/**
 * 获取学校封面列表
 * @param query
 */
const getOrganizationCoverList = (
    query: any,
): PromisePageResponse<SchoolSiteHomePageVo> => {
  return request({
    url: "/school/cover/list",
    method: "get",
    params: query,
  });
};

/**
 * 新建学校子站封面图片
 * @param query
 */
const createOrganizationCover = (query: any): PromiseResponse<any> => {
  return request({
    url: "/school/cover",
    method: "post",
    data: query,
  });
};

/**
 * 修改学校子站封面图片
 * @param query
 */
const updateOrganizationCover = (query: any): PromiseResponse<any> => {
  return request({
    url: "/school/cover/edit",
    method: "put",
    data: query,
  });
};


// 获取轮播图列表
const getOrganizationSwiperList = (query: any): PromiseResponse<any> => {
  return request({
    url: "/course/carousel/list",
    method: "get",
    params: query,
  })
}

/**
 * 获取学校新闻列表
 * @param query
 */
const getSchoolNewsList = (
  query: any,
): PromisePageResponse<SchoolSiteArticleVo> => {
  return request({
    url: "/school/article/list",
    method: "get",
    params: query,
  });
};

/**
 * 修改学校新闻
 * @param query
 */
const setSwiper = (query: any): PromiseResponse<any> => {
  return request({
    url: "/school/article/edit",
    method: "put",
    data: query,
  });
};

/**
 * 新增学校新闻
 * @param query
 */
const addSchoolNews = (query: any): PromiseResponse<any> => {
  return request({
    url: "/school/article",
    method: "post",
    data: query,
  });
};

/**
 * 获取学校新闻详情
 * @param newsId
 */
const getSchoolNewsDetail = (
  newsId: any,
): PromiseResponse<SchoolSiteArticleVo> => {
  return request({
    url: `/school/article/${newsId}`,
    method: "get",
  });
};
 
/**
 * 删除学校新闻
 * @param newsId
 */
const deleteSchoolNews = (newsId: string | string[]) => {
  return request({
    url: `/school/article/${newsId}`,
    method: "delete",
  });
};


export {
  getRootOrganizationList,
  getRootOrganizationTypeList,
  getOrganizationCoverList,
  createOrganizationCover,
  updateOrganizationCover,
  getOrganizationSwiperList,
  getSchoolNewsList,
  setSwiper,
  addSchoolNews,
  getSchoolNewsDetail,
  deleteSchoolNews
};
